package com.es.hr.visitorscore;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

import com.es.hr.shop.ShopBean;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;

public class VisitorScoreModifyDoAction extends ActionSupport implements ServletRequestAware {
	HttpServletRequest request;

	public void setServletRequest(HttpServletRequest paramHttpServletRequest) {
		this.request = paramHttpServletRequest;
	}
	
	public String execute() throws Exception{
		String result = "";
		VisitorScoreBiz biz = new VisitorScoreBiz();
		
		VisitorScoreBean bean= this.getBean(request);
		
		boolean res = biz.updateVisitorScore(bean);
		if(res == true){
			result = "success";
			String message = "修改成功";
			this.request.setAttribute("message", message);
		}else{
			result = "success";
			String message = "修改失败，请重新添加";
			this.request.setAttribute("message", message);
		}
		return result;
	}
	public VisitorScoreBean getBean(HttpServletRequest request) throws SecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException{
		Field[] fds = Class.forName("com.es.hr.visitorscore.VisitorScoreBean").getDeclaredFields();   
		VisitorScoreBean bean = new VisitorScoreBean();
		 
		  for(int i=0;i<fds.length;i++)   
		  {   
			  String d= fds[i].getName();
			  fds[i].set(bean, request.getParameter(d));
		  }
		  return bean;
	}
}
